#include <cstdio>
using namespace std;

const int MOD = 20100713;
const int MAX = 10000001;

int F[ MAX ] = {0};
int maxF = 1;

int factorial( int n )
{
	if( n <= maxF ) return F[n];
	long long r = F[maxF];
	for( int i = maxF + 1; i <= n; i++ )
	{
		r = r * i;
		if( r > MOD ) r %= MOD;
		F[i] = r;
	}
	maxF = n;
	return r;
}

long long power( long long n, int m )
{
	if( n == 0 ) return 0;
	if( n == 1 ) return 1;
	if( m == 0 ) return 1;

	long long r = 1;
	while( m != 0 )
	{
		int k = ( m & 0x01 ) ? n : 1;
		r *= k;
		if( r > MOD ) r %= MOD;
		m >>= 1;
		if( m != 0 )
		{
			n *= n;
			if( n > MOD ) n %= MOD;
		}
	}
	return r;
}

int main()
{
	F[0] = 1;
	F[1] = 1;
	int cases = 0;
	scanf( "%d", &cases );
	while( cases-- )
	{
		long long n = 0, k = 0;
		scanf( "%lld %lld", &n, &k );

		long long f = power( k + 1, n - k ) - power( k, n - k );
		if( f < MOD ) f += MOD;
		f = ( f * factorial( k ) ) % MOD;
		printf( "%lld\n", f );
	}
	return 0;
}
